part of 'isar.dart';

mixin LocalDataWorkNoteInfo {
  List<WorkNoteInfo> notes = List.empty(growable: true);

  queryWorkNoteInfo() async {
    notes = await isar.workNoteInfos.where().sortByDateDesc().findAll() ?? [];
    print('notes:${notes.length}');
  }
}

extension ExtDataWorkNoteInfo on List<WorkNoteInfo> {
  save(WorkNoteInfo note) {
    isar.write((isar) async {
      isar.workNoteInfos.put(note);
    });
  }

  Future<bool> isExist(String date) async {
    int count = await isar.workNoteInfos.where().dateEqualTo(date).count();
    return count > 0;
  }

  delete(String date) {
    isar.write((isar) async {
      isar.workNoteInfos.where().dateEqualTo(date).deleteAll();
    });
  }
}
